package javaweek4;

import java.text.DecimalFormat;

class Person{
	private String name;
	private int age;
	private boolean gender;
	public Person(String name, int age, boolean gender) {
		this.name = name;
		this.age = age;
		this.gender = gender;
	}
	@Override
	public String toString() {
		return this.name+"-"+this.age+"-"+this.gender;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (age != other.age)
			return false;
		if (gender != other.gender)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
class Company{
	private String company;
	public Company(String company) {
		this.company = company;
	}
	@Override
	public String toString() {
		return this.company;
	}
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (company == null) {
			if (other.company != null)
				return false;
		} else if (!company.equals(other.company))
			return false;
		return true;
	}
}
class Employee extends Person{
	private Company company;
	private double salary;
	public Employee(String name, int age, boolean gender,double salary,Company company) {
		super(name, age, gender);
		this.company=company;
		this.salary=salary;
	}
	
	@Override
	public String toString() {
		return super.toString()+"-"+company.toString()+"-"+this.salary;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (!super.equals(other)) 
			return false;
		if (company == null) {
			if (other.company != null)
				return false;
		} else if (!company.equals(other.company))
			return false;
		DecimalFormat df = new DecimalFormat("#.##");
		if (df.format(salary)!=df.format(other.salary))
			return true;
		return true;
	}
	
}

public class Main {

    public static void main(String[] args) {
    	Company c1 = new Company("MicroSoft");
    	Company c2 = new Company("IBM");
    	Person e1 = new Employee("Li", 35, true, 60000.124, c1);
    	Person e2 = new Employee("Li", 35, true, 60000.124, c1);
    	Person e3 = new Employee("Li", 35, true, 60000.124, c2);
    	Person e4 = new Employee("Li", 35, true, 60000.123, c2);
    	Person e5 = new Employee("Li", 35, true, 60000.126, c2);
    	Person e6 = new Employee("Li", 35, true, 60000.126, null);
    	System.out.println(e1.equals(e2));
    	System.out.println(e1.equals(e3));
    	System.out.println(e3.equals(e4));
    	System.out.println(e3.equals(e5));
    	System.out.println(e5.equals(e6));
    }
}